Skip to content

Conversation

@karlseguin
Copy link
Collaborator

Page currently contains 5 URL-ish related fields:

    rawuri: ?[]const u8 = null,
    uri: std.Uri = undefined,
    origin: ?[]const u8 = null,

    url: ?URL = null,
    location: Location = .{},

This PR adds a new URL struct which contains both the raw string and the std.Uri, and encapsulates some of the std.Uri API. It also tries to clean up some of the ownership. For example, page no longer has a location field. Instead, the window owns the location. Similarly, page no longer has a url field, the location now owns its url.

I original made http/client.zig and storage/cookie.zig use the new URL struct, but I backed away from that change in this PR. However, I did change those two classes to use *const std.Uri rather than a std.Uri, again to try to clean up ownership.

I think there's more cleanup we can do around URI - the std.Uri API isn't great - so starting to encapsulate access through this custom struct is the first step.

Combine uri + rawuri into single struct.

Try to improve ownership around URIs and URI-like things.
 - cookie & request can take *const std.Uri
   (TODO: make them aware of the new URL struct?)
 - Location (web api) should own its URL (web api URL)
 - Window should own its Location

Most of these changes result in (a) a cleaner Page and (b) not having to carry
around 2 nullable objects (URI and rawuri).
const href = (try parser.elementGetAttribute(element, "href")) orelse return null;
var buf = try allocator.alloc(u8, 1024);
return .{ .navigate = try std.Uri.resolve_inplace(self.uri, href, &buf) };
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This deletion is not relative to the PR isn't it? you are preparing the change in #516?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this function returns a std.Uri, which gets converted to a string in input.clickNavigate, then back into a uri by page.navigate. Since this code isn't currently being used, and it'll get removed anyways, I didn't want to bother making it work with the new URL.


switch (click_result) {
.navigate => |uri| try clickNavigate(cmd, uri),
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same with this deletion

@krichprollsch krichprollsch merged commit 66bac32 into main Apr 9, 2025
12 checks passed
@krichprollsch krichprollsch deleted the url branch April 9, 2025 14:43
@github-actions github-actions bot locked and limited conversation to collaborators Apr 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants